package com.whut.work.score.controller;

import com.whut.work.base.model.Page;
import com.whut.work.score.model.Score;
import com.whut.work.score.service.IScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zouyao on 2017/3/15.
 */
@Controller
@RequestMapping("/score")
public class ScoreCtrl {

    @Autowired
    private IScoreService scoreService;

    @RequestMapping(value="/getScoreRecordByUserId",method= RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getScoreRecordByUserId(HttpServletRequest request,Integer studentId,Integer teacherId){
        Map<String,Object> returnMap = new HashMap<String,Object>();

        try {
            Map<String,Object> result = scoreService.getScoreRecordByUserId(studentId,teacherId);

            returnMap.put("value", result.get("value"));
            returnMap.put("message", result.get("message"));
            returnMap.put("success", true);
        } catch (Exception e) {
            returnMap.put("message", "异常：获取失败!");
            returnMap.put("success", false);
            e.printStackTrace();
        }
        return returnMap;
    }

    @RequestMapping(value="/setScoreForTeacher",method= RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> setScoreForTeacher(HttpServletRequest request,Integer score, Integer studentId, Integer teacherId){
        Map<String,Object> returnMap = new HashMap<String,Object>();

        try {
            Map<String,Object> result = scoreService.setScoreForTeacher(score,studentId,teacherId);

            returnMap.put("value", result.get("value"));
            returnMap.put("message", result.get("message"));
            returnMap.put("success", true);
        } catch (Exception e) {
            returnMap.put("message", "异常：操作失败!");
            returnMap.put("success", false);
            e.printStackTrace();
        }
        return returnMap;
    }

    @RequestMapping(value="/getScoreListOfOneTeacher",method= RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getScoreListOfOneTeacher(HttpServletRequest request,Integer currentPage, Integer pageSize,Integer id){
        Map<String,Object> returnMap = new HashMap<String,Object>();

        try {
            Page<Score> result = scoreService.getScoreListOfOneTeacher(currentPage,pageSize,id);

            returnMap.put("value", result);
            returnMap.put("message", "获取成功");
            returnMap.put("success", true);
        } catch (Exception e) {
            returnMap.put("message", "异常：操作失败!");
            returnMap.put("success", false);
            e.printStackTrace();
        }
        return returnMap;
    }

}
